package com.capitalbio.smd.base;

import org.biojava.bio.symbol.Symbol;

/**
 * Variation type
 * 
 * @author Wang Lei
 * 
 */
public enum VariationType {
	/**
	 * <p>
	 * Inversions
	 * </p>
	 * <p>
	 * Inversions are designated by "inv" after an indication of the first
	 * and last nucleotides affected by the inversion.
	 * </p>
	 * <p>
	 * <ul>
	 * <li>
	 * c.203_506inv (or 203_506inv304) denotes that the 304 nucleotides from
	 * position 203 to 506 have been inverted</li>
	 * </ul>
	 * </p>
	 */
	//INVERSION,

	/**
	 * <p>
	 * Conversions
	 * </p>
	 * <p>
	 * Conversions are designated by "con" after an indication of the first
	 * and last nucleotides affected by the conversion, followed by a
	 * description of the origin of the new nucleotides.
	 * </p>
	 * <p>
	 * <ul>
	 * <li>
	 * c.123_678conNM_004006.1:c.123_678 describes a gene conversion
	 * replacing nucleotides c.123 to c.4567 of the coding DNA sequence of
	 * the transcript of interest with nucleotides c.123 to c.678 from a
	 * transcript sequence as present in GenBank file NM_004006 (version 1)</li>
	 * </ul>
	 * </p>
	 */
	//CONVERSION,

	/**
	 * <p>
	 * Translocations
	 * </p>
	 * <p>
	 * Translocations are described at the molecular level using the format
	 * "t(X;4)(p21.2;q34)", followed by the usual numbering, indicating the
	 * position translocation breakpoint. The sequences of the translocation
	 * breakpoints need to be submitted to a sequence database (Genbank,
	 * EMBL, DDJB) and the accession.version numbers should be given.
	 * </p>
	 * <p>
	 * <ul>
	 * <li>
	 * t(X;4)(p21.2;q35)(c.857+101_857+102) denotes a translocation
	 * breakpoint in the intron between coding DNA nucleotides 857+101 and
	 * 857+102, joining chromosome bands Xp21.2 and 4q34</li>
	 * </ul>
	 * </p>
	 */
	//TRANSLOCATION,

	/**
	 * <p>
	 * Deletions & insertions (indels)
	 * </p>
	 * <p>
	 * Deletion/insertions (indels) are described as a deletion followed by
	 * an insertion after an indication of the nucleotides flanking the site
	 * of the deletion/insertion. Changes of two or more consecutive
	 * nucleotides are described as deletion/insertions (indels).
	 * </p>
	 * <p>
	 * <ul>
	 * <li>
	 * c.112_117delinsTG (alternatively c.112_117delAGGTCAinsTG) denotes the
	 * replacement of nucleotides 112 to 117 (AGGTCA) by TG</li>
	 * <li>
	 * c.114_115delinsA (alternative c.[114G>A; 115delT])</li>
	 * </ul>
	 * </p>
	 */
	//DELETION_INSERTION,

	/**
	 * <p>
	 * Duplications
	 * </p>
	 * <p>
	 * Duplications are designated by "dup" after an indication of the first
	 * and last nucleotide(s) duplicated.
	 * </p>
	 * <p>
	 * <ul>
	 * <li>
	 * c.77_79dup (or c.77_79dupCTG, c.77_79dup3) denotes that the three
	 * nucleotides 77 to 79 are duplicated</li>
	 * <li>
	 * duplicating insertions of a mono-nucleotide and of extensions of di-,
	 * tri-, etc. nucleotide stretches should be described as duplications
	 * <ul>
	 * <li>
	 * c.5dupT (or c.5dup) denotes a duplication ("insertion") of the T
	 * nucleotide at position 5 in the coding DNA sequence ACTCTGTGCC to
	 * ACTCTTGTGCC</li>
	 * <li>
	 * c.5dupT (or c.5dup) denotes a duplication ("insertion") of the T
	 * nucleotide at position 5 in the coding DNA sequence ACTTTGTGCC to
	 * ACTTTTGTGCC</li>
	 * <li>
	 * c.7_8dup (or c.7_8dupTG) or c.7_8dup2) denotes a TG duplication in
	 * the TG-tandem repeat sequence of ACTTTGTGCC to ACTTTGTGTGCC. <br>
	 * <b>NOTE:</b> this change should not be described as an insertion,
	 * i.e. c.8_9insTG</li>
	 * </ul>
	 * </li>
	 * <li>
	 * c.(?_-30)_(*220_?)dup denotes the duplication of the entire gene
	 * (coding DNA reference sequence running from -30 (cap site) to *220
	 * (polyA-addition site)</li>
	 * <li>
	 * c.32-?_357+?[3] denotes a triplication of an exon (coding DNA
	 * reference sequence running from nucleotide 32 to 357) <br>
	 * <b>NOTE:</b> the use of tri (for triplication), qua (for
	 * quadruplication), etc. is not recommended</li>
	 * </ul>
	 * </p>
	 */
	//DUPLICATION,

	/**
	 * <p>
	 * Variability of short sequence repeats
	 * </p>
	 * <p>
	 * Variability of short sequence repeats (e.g. ATGCGATGTGTGCC) are
	 * described as c.123+74TG(3_6); c.123+74 indicates the start of the
	 * first nucelotide of the variable repeat (not the end like c.123+79TG)
	 * and TG indicates the sequence of the repeat unit. <br>
	 * <b>NOTE:</b> the underscore is used to indicate the range (3 to 6
	 * times); when the repeat-sequence becomes too large its size is
	 * indicated, not its range.
	 * </p>
	 * <p>
	 * <ul>
	 * <li>
	 * c.1210-12T(5_9) describes a famous variable stretch of 5 to 9
	 * T-residues in intron 9 of the CFTR gene. The most commonly used CFTR
	 * coding DNA Reference Sequence contains a stretch of 7 T's. It is
	 * recommended to describe individual alleles differing from this
	 * reference sequence as c.1210-12T[5] (not c.1210-7_1210-6delTT) or
	 * c.1210-12T[9] (not c.1210-7_1210-6dupTT). <br>
	 * <b>NOTE:</b> the repeat should not be described as c.1210-6T(5_9)</li>
	 * <li>
	 * c.123+74TG(3_6) (alternatively c.123+74_123+75(3_6)) indicates that a
	 * TG di-nucleotide repeat is present, starting at nucleotide 74 in the
	 * intron following cDNA nucelotide c.123, which is found repeated 3 to
	 * 6 times in the population</li>
	 * <li>
	 * c.123+74TG[4]+[5] denotes that a person carries a TG di-nucleotide
	 * repeat of length 4 on one allele and of length 5 on the other allele</li>
	 * <li>
	 * based on the FMR1 coding DNA Reference Sequence (GenBank
	 * NM_002024.3), c.-158GGC(1000) describes the presence of an extended
	 * GGC-repeat of about 1000 units <br>
	 * <b>NOTE:</b> "()" is used to indicate uncertainties</li>
	 * <li>
	 * c.-158GGC[79] describes the presence of an extended GGC-repeat of
	 * exactly 79 units</li>
	 * <li>
	 * c.32-?_357+?[3] denotes a triplication of an exon ( coding DNA
	 * reference sequence running from nucleotide 32 to 357) <br>
	 * <b>NOTE:</b> the use of tri (for triplication), qua (for
	 * quadruplication), etc. is not recommended</li>
	 * <li>
	 * g.1209_4523(12_45) denotes that a 3.3 kb repeat sequence of which the
	 * first copy is present in the genomic reference sequence from
	 * nucleotides 1209 to 4523 can be found repeated 12 to 45 times in the
	 * population</li>
	 * </ul>
	 * </p>
	 */
	//REPEAT

	/**
	 * <p>
	 * Deletions
	 * </p>
	 * <p>
	 * Deletions are designated by "del" after an indication of the first
	 * and last nucleotide(s) deleted.
	 * </p>
	 * <p>
	 * <ul>
	 * <li>
	 * c.76_78del (alternatively c.76_78delACT) denotes a ACT deletion from
	 * nucleotides 76 to 78</li>
	 * <li>
	 * c.7_8del (alternatively c.7_8delTG) denotes a TG deletion in the
	 * sequence ACTTTGTGCC to ACTTTGCC</li>
	 * <li>
	 * c.88-?_923+?del denotes an exonic deletion starting at an unknown
	 * position in the intron 5' of coding DNA nucleotide 88 and ending at
	 * an unknown position in the intron 3' of coding DNA nucleotide 923</li>
	 * <li>
	 * c.(?_-30)_(*220_?)del denotes the deletion of the entire gene (coding
	 * DNA reference sequence running from -30 (cap site) to *220
	 * (polyA-addition site)</li>
	 * <li>
	 * c.88+101_oGJB2:c.355-1045del denotes a deletion which ends in the
	 * flanking GJB2 gene at position 355-1045 (in the intron between
	 * nucleotides 354 and 355) on the reverse strand (the genes are thus
	 * located and fused in opposite transcriptional directions)</li>
	 * <li>
	 * for all descriptions the most 3' position possible is arbitrarily
	 * assigned to have been changed;
	 * <ul>
	 * <li>
	 * ACTTTGTGCC to ACTTGCC is described as c.5_7delTGT (not as
	 * c.4_6delTTG).</li>
	 * <li>
	 * ctttagGCATG to cttagGTCCA in an intron is described as c.301-3delT
	 * (not as c.301-5delT)</li>
	 * <li>
	 * TCACTGTCTGCGGTAATC to TCACTG CGGTAATC is described as c.7_10del
	 * (alternatively c.7_10delTCTG) and not as c.4_7delCTGT</li>
	 * <li>
	 * AAAGAAGAGGAG to AAAG GAG is described as c.5_9del (alternatively
	 * c.5_9delAAGAG) and not as c.3_7delAGAAG</li>
	 * <li>
	 * Exception
	 * <ul>
	 * <li>
	 * c.1210-12T(5_9) and not c.1210-6T(5_9)describes the variable stretch
	 * of 5 to 9 T-residues in intron 9 of the CFTR gene. The most commonly
	 * used CFTR coding DNA Reference Sequence contains a stretch of 7 T's.
	 * <br>
	 * <b>NOTE:</b> to discriminate known variable sequences from other
	 * changes it is recommended to describe individual alleles differing
	 * from the reference sequence like c.1210-12T[5] (preferred over
	 * c.1210-7_1210-6delTT) or c.1210-12T[9] (preferred over
	 * c.1210-7_1210-6dupTT).</li>
	 * <li>
	 * using a coding DNA Reference Sequence there is an exception to this
	 * rule when identical nucleotides flank an intron (e.g. exon 3 ends
	 * with ..CAAgt, exon 4 starts with agAAG.., C being nucleotide c.123).
	 * When the genomic sequence shows that the last A-nucleotide of exon 3
	 * is deleted (and not the A-nucleotide in exon 4), the deletion
	 * changing ..CAAAAG.. to ..CA AAG.. is described as c.125delA and not
	 * c.127delA.</li>
	 * </ul>
	 * </li>
	 * </ul>
	 * </ul>
	 * </p>
	 */
	DELETION,

	/**
	 * <p>
	 * Insertions
	 * </p>
	 * <p>
	 * Insertions are designated by "ins" after an indication of the
	 * nucleotides flanking the insertion site, followed by a description of
	 * the nucleotides inserted. Duplicating insertions should be described
	 * as duplications, not as insertion. For large insertions the number of
	 * inserted nucleotides should be mentioned, together with an
	 * accession.version number referring to a sequence database file
	 * containing the complete inserted sequence.
	 * </p>
	 * <p>
	 * <ul>
	 * <li>
	 * c.76_77insT denotes that a T is inserted between nucleotides 76 and
	 * 77 of the coding DNA reference sequence</li>
	 * <li>
	 * c.123+54_123+55insAB012345.2:g.76_420 (or c.123+54_123+55ins345,
	 * GenBank AB012345.2) denotes an intronic insertion ( between
	 * nucleotides c.123+54 and 123+55) of 345 nucleotides (nucleotides 76
	 * to 420 like in GenBank file AB012345 version 2)</li>
	 * </ul>
	 * </p>
	 */
	INSERTION,
	
	/**
	 * <p>
	 * Substitutions
	 * </p>
	 * <p>
	 * <ul>
	 * <li>
	 * Single nucleotide substitutions are designated by a ">"-character
	 * (indicating "changes to"). Changes of two or more consecutive
	 * nucleotides are described as deletion/insertions.</li>
	 * <li>
	 * c.76A>C denotes that at nucleotide 76 an A is changed to a C</li>
	 * <li>
	 * c.-14G>C denotes a G to C substitution 14 nucleotides 5' of the ATG
	 * translation initiation codon</li>
	 * <li>
	 * c.88+1G>T denotes the G to T substitution at nucleotide +1 of an
	 * intron (in the coding DNA positioned between nucleotides 88 and 89)</li>
	 * <li>
	 * c.89-2A>C denotes the A to C substitution at nucleotide -2 of an
	 * intron (in the coding DNA positioned between nucleotides 88 and 89)</li>
	 * <li>
	 * c.*46T>A denotes a T to A substitution 46 nucleotides 3' of the
	 * translation termination codon</li>
	 * <li>
	 * the description c.76_77delinsTT is preferred over c.[76A>T; 77G>T]. <br>
	 * <b>NOTE:</b> it is not correct to describe polymorphic variants as
	 * c.76A/G.</li>
	 * </ul>
	 * </p>
	 */
	SUBSTITUTION;
	
	/**
	 * Parse string to variation type
	 * @param variationTypeStr the variation type string
	 * @return the parsed variation type
	 */
	public static VariationType parseVariationType(String variationTypeStr) {
		if (variationTypeStr.indexOf("del") != -1) {
			return DELETION;
		}
		else if (variationTypeStr.indexOf("ins") != -1) {
			return INSERTION;
		}
		else if (variationTypeStr.indexOf(">") != -1) {
			return SUBSTITUTION;
		}
		else {
			throw new IllegalArgumentException("Not a llegal variation type string.");
		}
	}
	
	/**
	 * Parse symbol type by reference symbol and sequencing symbol
	 * @param symbol0 reference symbol
	 * @param symbol1 user symbol
	 */
	public static VariationType parseVariationType(Symbol symbol0, Symbol symbol1) {
		if (symbol0.equals(symbol1)) {
			return null;
		}
		if (symbol0.equals(Util.getGapSymbol())) {
			return INSERTION;
		}
		if (symbol1.equals(Util.getGapSymbol())) {
			return DELETION;
		}
		return SUBSTITUTION;
	}
}
